import sqlite3
import tkinter
from tkinter import *
from tkinter.messagebox import *

conn = sqlite3.connect('test.db')
cursor = conn.cursor()
cursor.execute('select * from exam')
values = cursor.fetchall()
cursor.close()
conn.close()


def callNext():
    global k
    global score
    useranswer = r.get()
    print(r.get())
    if useranswer == values[k][5]:
        showinfo("恭喜", "恭喜你对了！")
        score += 10
    else:
        showinfo("Sorry", "遗憾你错了！")
    k = k + 1
    if k >= len(values):
        showinfo("提示", "题目做完了！")
        return
    timu["text"] = values[k][0]
    radio1["text"] = values[k][1]
    radio2["text"] = values[k][2]
    radio3["text"] = values[k][3]
    radio4["text"] = values[k][4]
    r.set('E')


def callResult():
    showinfo("你的得分：", str(score))


# 界面设置
root = tkinter.Tk()
root.title("Python智力问答游戏")
root.geometry("500x200")
r = tkinter.StringVar()
r.set('E')
k = 0
score = 0
timu = tkinter.Label(root, text=values[k][0])
timu.pack()
f1 = Frame(root)
f1.pack()
radio1 = tkinter.Radiobutton(f1, variable=r, value='A', text=values[k][1])
radio1.pack()
radio2 = tkinter.Radiobutton(f1, variable=r, value='B', text=values[k][2])
radio2.pack()
radio3 = tkinter.Radiobutton(f1, variable=r, value='C', text=values[k][3])
radio3.pack()
radio4 = tkinter.Radiobutton(f1, variable=r, value='D', text=values[k][4])
radio4.pack()
f2 = Frame(root)
f2.pack()
Button(f2, text='下一题', command=callNext).pack(side=LEFT)
Button(f2, text='结 果', command=callResult).pack(side=LEFT)
root.mainloop()
